home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / amos / AMOS0398.lzh / AMOSLIST / 000044_amos-request@svcs1.digex.net_Thu Mar 5 05:34:10 1998.msg < prev    next >
Text File  |  1998-04-01  |  5KB  |  155 lines

  1. >From amos-request@svcs1.digex.net  Thu Mar  5 05:34:09 1998
  2. Received: from svcs1.digex.net (svcs1.digex.net [204.91.197.224])
  3.     by pony-1.mail.digex.net (8.8.8/8.8.8) with ESMTP id FAA22215
  4.     for <mcox@access.digex.net>; Thu, 5 Mar 1998 05:34:09 -0500 (EST)
  5. Received: (from daemon@localhost)
  6.     by svcs1.digex.net (8.8.5/8.8.5) id EAA20423
  7.     for amos-out; Thu, 5 Mar 1998 04:01:38 -0500 (EST)
  8. Received: from pony-2.mail.digex.net (pony-2.mail.digex.net [204.91.241.6])
  9.     by svcs1.digex.net (8.8.5/8.8.5) with ESMTP id EAA20420
  10.     for <amos-list@svcs1.digex.net>; Thu, 5 Mar 1998 04:01:38 -0500 (EST)
  11. Received: from mailhost.sosbbs.com (sosbbs.com [204.186.168.100])
  12.     by pony-2.mail.digex.net (8.8.8/8.8.8) with SMTP id EAA24276
  13.     for <amos-list@access.digex.net>; Thu, 5 Mar 1998 04:01:34 -0500 (EST)
  14. Received: from default (204.186.168.51) by mailhost.sosbbs.com
  15.  (EMWAC SMTPRS 0.81) with SMTP id <B0000224869@mailhost.sosbbs.com>;
  16.  Thu, 05 Mar 1998 03:58:05 -0500
  17. Message-ID: <B0000224869@mailhost.sosbbs.com>
  18. From: "Garfield Benjamin" <gbenjam@sosbbs.com>
  19. To: "AMOS MAILING LIST" <amos-list@access.digex.net>
  20. Subject: Re: need help rotating a map!!
  21. Date: Thu, 5 Mar 1998 04:12:01 -0500
  22. X-MSMail-Priority: Normal
  23. X-Priority: 3
  24. X-Mailer: Microsoft Internet Mail 4.70.1155
  25. MIME-Version: 1.0
  26. Content-Type: text/plain; charset=ISO-8859-1
  27. Content-Transfer-Encoding: 7bit
  28. Status: O
  29. X-Status: 
  30.  
  31. > I'm making a dungeon game its levels are 50x50 stored in an array
  32. > I need some code to rotate this map 90 degrees in either direction..
  33.  
  34.    For the sake of simplicity, the code below assumes you're useing a
  35.    two-dimensional array to store your map.  Obviously, a one-
  36.    dimensional array or particularly a binary array would be more
  37.    effiecient, but you can apply the design to whatever method you're
  38.    actually using...
  39.  
  40.    Okay, the idea is simple enough.  To rotate your map counter clock
  41.    wise, you need to transfer the map rows (top to bottom) to the map
  42.    cols (left to right)...
  43.    ABCDE                       EJOTY
  44.    FGHIJ                        DINSX
  45.    KLMNO                      CHMRW
  46.    PQRST                      BGLQV
  47.    UVWXY                     AFKPU
  48.  
  49.    And for clockwise rotation, you simply transfer the map rows (top to
  50.    bottom) to the map cols (right to left)...
  51.    ABCDE                      UPKFA
  52.    FGHIJ                       VQLGB
  53.    KLMNO                     WRMHC
  54.    PQRST                      XSNID
  55.    UVWXY                     YTOJE
  56.  
  57.    Of course, that is simply the way I am viewing it, you could look 
  58.    at the process in a number of ways, but moving on to the code...:)
  59.  
  60.    BTW- I'm on my PC and just did a quick test in C (these routines\
  61.              work fine), so if I make some syntax errors in the AMOS
  62.              version (created on the fly below), you'll know why...
  63.  
  64.   I'm going to use a 5x5 matrix for this example, as my creation code
  65.   fills a 5x5 MAP with the characters in the above examples...
  66.   just change the MAPWIDTH and MAPHEIGHT values to 50.
  67.  
  68.   --------<CODE STARTS HERE>--------  
  69.   Dim MAP(50,100) : Rem Double-height BUFFERED map...
  70.   Shared MAP(), MAPBASE, MAPWIDTH, MAPHEIGHT
  71.  
  72.   Procedure ROTATEMAPLEFT
  73.     DESTBASE=MAPHEIGHT-MAPBASE
  74.     DESTCOL=0
  75.     For REP=0 To MAPHEIGHT-1
  76.       SOURCEROW=MAPBASE+REP
  77.       DESTROW=DESTBASE+(MAPHEIGHT-1)
  78.       For SOURCECOL=0 To MAPWIDTH-1
  79.         MAP(DESTCOL,DESTROW)=MAP(SOURCECOL,SOURCEROW)
  80.         Dec DESTROW
  81.       Next SOURCECOL
  82.       Inc DESTCOL
  83.     Next REP
  84.     MAPBASE=DESTBASE  
  85.   End Proc
  86.  
  87.  Procedure ROTATEMAPRIGHT
  88.     DESTBASE=MAPHEIGHT-MAPBASE
  89.     DESTCOL=MAPWIDTH-1
  90.     For REP=0 To MAPHEIGHT-1
  91.       SOURCEROW=MAPBASE+REP
  92.       DESTROW=DESTBASE
  93.       For SOURCECOL=0 To MAPWIDTH-1
  94.         MAP(DESTCOL,DESTROW)=MAP(SOURCECOL,SOURCEROW)
  95.         Inc DESTROW
  96.       Next SOURCECOL
  97.       Dec DESTCOL
  98.     Next REP
  99.     MAPBASE=DESTBASE  
  100.   End Proc
  101.  
  102.   Procedure MAPVIEW
  103.     For YPOS=0 To MAPHEIGHT-1
  104.       Print "          ";
  105.       For XPOS=0 To MAPWIDTH-1
  106.         Print Chr$(MAP(XPOS,MAPBASE+YPOS));
  107.       Next XPOS
  108.       Print
  109.     Next YPOS
  110.   End Proc 
  111.  
  112.   ' ----------------------------
  113.   ' MAIN CODE HERE
  114.   '-----------------------------
  115.   MAPBASE=0 : Rem Toggled between 0 and 5 for buffering
  116.   MAPWIDTH=5 : MAPHEIGHT=5
  117.  
  118.   Print "Initializing Map..." : PRINT
  119.   TILE=Asc("A")
  120.   For YPOS=0 To MAPHEIGHT-1
  121.     For XPOS=0 To MAPWIDTH-1
  122.       MAP(XPOS,MAPBASE+YPOS)=TILE 
  123.       Add TILE,1,Asc("A") To Asc("Z")
  124.     Next XPOS
  125.   Next YPOS
  126.  
  127.   Print "Map defined as follows:"
  128.   MAPVIEW
  129.  
  130.   Print "Original Map rotated CounterClockWise:"
  131.   ROTATEMAPLEFT
  132.   MAPVIEW
  133.  
  134.   Print "Original Map rotated ClockWise:"
  135.   ROTATEMAPRIGHT : ROTATEMAPRIGHT
  136.   MAPVIEW
  137.  
  138.   Wait Key
  139.   End
  140.   --------<CODE ENDS HERE>--------
  141.   
  142.   Everytime you call these rotation functions, the MAPBASE is 
  143.   changed, so you'll need to use MAPBASE+ROW to access your map.
  144.   I used a buffered design as this is faster than having to copy your
  145.   MAP into a temporary workbuffer then rotate "back" to the MAP
  146.   array...
  147.  
  148.   Anyway, hope this helps... :-)
  149.  
  150.  
  151.  
  152.                 Garfield Benjamin    e-mail:gbenjam@sosbbs.com
  153.                     VerticalShooter(PC): 52% complete(...23 days)
  154.       NEW!! (DemoVersion0.52 available on my GAMES-page) NEW!!
  155.         Website( http://www.sosbbs.com/~gbenjam ): 50% Complete